<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"
	template="/templates/template.xhtml" xmlns:eq="http://www.equus.com.br/facelets/">

	<f:metadata>
		<f:event type="preRenderView" listener="#{matrizBean.verificarAcesso}" />
	</f:metadata>

	<ui:define name="body">
		<h:form id="form" prependId="false">
			<h:panelGrid id="tagOs" width="100%">
				<eq:animal animal="#{matrizBean.animal}" />
			</h:panelGrid>
			<p:fieldset legend="#{matrizBean.qualifiedName}" id="fieldPrincipal">
				<h:panelGrid columns="4" id="panelCadastro" columnClasses="coluna25,coluna30,coluna20,coluna35" width="100%">

					<h:outputLabel value="Garanhão:" for="garanhao" styleClass="icoObrigatorio" />
					<p:autoComplete queryDelay="500" size="90" value="#{matrizBean.garanhao}"
						completeMethod="#{matrizBean.completeAnimal}" var="animal" forceSelection="true" itemLabel="#{animal.nome}"
						itemValue="#{animal.id}" converter="animalConverter" multiple="false" id="garanhao"
						requiredMessage="#{matrizBean.requiredMessage}" required="true">
						<p:column style="width:20%;text-align:center">
							<p:graphicImage value="/imagemServlet?file=#{animal.urlImagemAleatoria}" width="40" height="50"
								rendered="#{animal.urlImagemAleatoria != null and !empty animal.urlImagemAleatoria}" />
						</p:column>
						<p:column style="width:60%">
							<h:outputText value="#{animal.nome}" />
						</p:column>
						<p:column style="width:20%">
							<h:outputText value="#{animal.sexoFormat}" />
						</p:column>
					</p:autoComplete>

					<p:message for="garanhao" />
					<h:outputText value=" " />


					<h:outputText value="Data Inseminação:" styleClass="icoObrigatorio" />
					<h:panelGrid columns="2" cellpadding="0" cellspacing="0">
						<p:calendar locale="pt" pattern="dd/MM/yyyy" id="dtInse" navigator="true" maxlength="10" size="15"
							readOnlyInputText="true" value="${matrizBean.model.dtInseminacao}" mode="popup" showOn="button"
							requiredMessage="#{matrizBean.requiredMessage}" required="true" />
						<p:commandLink process="@this" title="Limpar" update="dtInse">
							<h:graphicImage name="icone-limpar.png" library="design/imagem" />
							<f:setPropertyActionListener target="${matrizBean.model.dtInseminacao}" value="" />
						</p:commandLink>
					</h:panelGrid>
					<p:message for="dtInse" />
					<h:outputText value=" " />

					<h:outputText value="Data Previsão do Parto:" styleClass="icoObrigatorio" />
					<h:panelGrid columns="2" cellpadding="0" cellspacing="0">
						<p:calendar locale="pt" pattern="dd/MM/yyyy" id="dtPrevParto" navigator="true" maxlength="10" size="15"
							readOnlyInputText="true" value="#{matrizBean.model.dtPrevParto}" mode="popup" showOn="button"
							requiredMessage="#{matrizBean.requiredMessage}" required="true" />
						<p:commandLink process="@this" title="Limpar" update="dtPrevParto">
							<h:graphicImage name="icone-limpar.png" library="design/imagem" />
							<f:setPropertyActionListener target="#{matrizBean.model.dtPrevParto}" value="" />
						</p:commandLink>
					</h:panelGrid>
					<p:message for="dtPrevParto" />
					<h:outputText value=" " />

					<h:outputLabel value="Observação:" />
					<p:inputTextarea value="#{matrizBean.model.observacao}" id="obs" cols="60" rows="6" autoResize="false" />
					<p:message for="obs" />
					<h:outputText value=" " />

				</h:panelGrid>
				<br />
			</p:fieldset>

			<p:toolbar>
				<p:toolbarGroup align="left">
					<p:commandButton value="Voltar" immediate="true" ajax="false" action="pesquisarAnimal.jsf" />
					<p:commandButton value="Limpar" immediate="true" ajax="false" action="#{matrizBean.limparTela}" />
					<p:commandButton rendered="#{p:ifGranted('ROLE_MATRIZ_SALVAR')}" value="Salvar" ajax="true" process="@form"
						update="@form" action="#{matrizBean.save}" />
				</p:toolbarGroup>
			</p:toolbar>
			<br />
			<p:dataTable var="lista" id="lista" emptyMessage="#{matrizBean.emptyMessage}" update="lista"
				rowsPerPageTemplate="#{matrizBean.paginacao}" styleClass="coluna100" value="#{matrizBean.lazyDataModel}"
				paginator="true" rows="5" rowStyleClass="#{empty rowIx or rowIx mod 2 ne 0 ? 'linhaImpar' : 'linhaPar'}"
				rowIndexVar="rowIx">


				<p:column headerText="Garanhão" sortBy="#{lista.animalGaranhao.nome}" filterBy="#{lista.animalGaranhao.nome}"
					style="width:26%">
					<h:outputLabel value="#{lista.animalGaranhao.nome}" />
				</p:column>
				<p:column headerText="Inseminação" sortBy="#{lista.dtInseminacao}" style="width:15%">
					<h:outputLabel value="#{lista.dtInseminacao}">
						<f:convertDateTime pattern="dd/MM/yyyy" />
					</h:outputLabel>
				</p:column>
				<p:column headerText="Previsão Parto" sortBy="#{lista.dtPrevParto}" style="width:15%">
					<h:outputLabel value="#{lista.dtPrevParto}">
						<f:convertDateTime pattern="dd/MM/yyyy" />
					</h:outputLabel>
				</p:column>
				<p:column headerText="Parto" sortBy="#{lista.dtParto}" style="width:15%">
					<h:outputLabel value="#{lista.dtParto}">
						<f:convertDateTime pattern="dd/MM/yyyy" />
					</h:outputLabel>
				</p:column>
				<p:column headerText="Embrião Efetivado" style="width:15%">
					<h:outputText value="#{lista.flgEmbriaoEfetivadoFormat}" />
				</p:column>
				<p:column headerText="Ações" style="width:13%;text-align:center;">
					<p:commandLink rendered="#{lista.flgEmbriaoEfetivado == null and p:ifGranted('ROLE_MATRIZ_EFETIVAR_EMBRIAO') }"
						title="Parto" process="@this" oncomplete="confirmationEfeito.show()">
						<h:graphicImage library="design/imagem" name="icone-cavalo.png" />
						<f:setPropertyActionListener target="#{matrizBean.animalEfetivado}" value="#{lista}" />
					</p:commandLink>
					<p:commandLink rendered="#{lista.flgEmbriaoEfetivado != null }" update=":form:popupEmbriaoVisu"
						title="Visualizar Parto" process="@this" oncomplete="confirmationEfeitoVisu.show()">
						<h:graphicImage library="design/imagem" name="icone-visualizar-parto.png" />
						<f:setPropertyActionListener target="#{matrizBean.animalEfetivado}" value="#{lista}" />
					</p:commandLink>
					<p:commandLink rendered="#{p:ifGranted('ROLE_MATRIZ_EDITAR')}" title="Editar" style="padding:5px !important;"
						update=":form:panelCadastro" process="@this" action="#{matrizBean.load}">
						<h:graphicImage library="design/imagem" name="icone-editar.png" />
						<f:setPropertyActionListener target="#{matrizBean.model}" value="#{lista}" />
					</p:commandLink>
					<p:commandLink rendered="#{p:ifGranted('ROLE_MATRIZ_EXCLUIR')}" title="Excluir" process="@this"
						oncomplete="confirmation.show()">
						<h:graphicImage library="design/imagem" name="icone-excluir.png" />
						<f:setPropertyActionListener target="#{matrizBean.model}" value="#{lista}" />
					</p:commandLink>
				</p:column>
			</p:dataTable>

			<p:confirmDialog appendToBody="true" message="Confirma a Exclusão" header="Exclusão" severity="alert"
				widgetVar="confirmation">
				<h:panelGrid columns="2">
					<p:commandButton value="Sim" update="lista,tagOs" oncomplete="confirmation.hide()"
						actionListener="#{matrizBean.delete}" immediate="true" />
					<p:commandButton value="Não" onclick="confirmation.hide()" />
				</h:panelGrid>
			</p:confirmDialog>


			<p:dialog appendToBody="false" header="Parto Realizado?" id="popupEmbriao" widgetVar="confirmationEfeito" width="450"
				height="200">
				<br />
				<h:panelGrid columns="2" id="panelParto" columnClasses="coluna40,coluna60" width="100%">
					<h:outputLabel value="Parto Realizado " styleClass="icoObrigatorio" />
					<p:selectOneRadio id="options" value="#{matrizBean.parto}">
						<f:selectItem itemLabel="Sim" itemValue="1" />
						<f:selectItem itemLabel="Não" itemValue="2" />
					</p:selectOneRadio>

					<h:outputText value="Data:" styleClass="icoObrigatorio" />
					<h:panelGrid columns="2" cellpadding="0" cellspacing="0">
						<p:calendar locale="pt" pattern="dd/MM/yyyy" id="dtParto" navigator="true" maxlength="10" size="15"
							readOnlyInputText="true" value="${matrizBean.data}" mode="popup" showOn="button" />
						<p:commandLink process="@this" title="Limpar" update="dtParto">
							<h:graphicImage name="icone-limpar.png" library="design/imagem" />
							<f:setPropertyActionListener target="${matrizBean.data}" value="" />
						</p:commandLink>
					</h:panelGrid>

				</h:panelGrid>
				<br />
				<br />
				<div align="center">
					<p:commandButton value="Salvar" ajax="true" process="popupEmbriao" action="#{matrizBean.saveEfetivo}" />
					<p:commandButton value="Fechar" immediate="true" onclick="confirmationEfeito.hide()" />
				</div>
			</p:dialog>

			<p:dialog appendToBody="true" header="Parto Realizado?" id="popupEmbriaoVisu" widgetVar="confirmationEfeitoVisu"
				width="450" height="200">
				<br />
				<h:panelGrid columns="2" id="panelPartoVisu" columnClasses="coluna40,coluna60" width="100%">
					<h:outputLabel value="Parto Realizado " />
					<h:outputLabel value="#{matrizBean.animalEfetivado.flgEmbriaoEfetivadoFormat}" />

					<h:outputText value="Data:" />
					<h:outputLabel value="#{matrizBean.animalEfetivado.dtParto}">
						<f:convertDateTime pattern="dd/MM/yyyy" />
					</h:outputLabel>
				</h:panelGrid>
				<br />
				<br />
				<div align="center">
					<p:commandButton value="Fechar" immediate="true" onclick="confirmationEfeitoVisu.hide()" />
				</div>
			</p:dialog>


		</h:form>
	</ui:define>
</ui:composition>